﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EAEcoreAddin.SQLWrapperClasses
{
    /*
     *Created by Alexander Schleich
     *for EMoflon:
     *http://www.moflon.org/emoflon/
     */
    class EAMethod : EA.Method
    {

        SQLRepository repository;
        String xmlMethodEntry;
        public EAMethod(String xmlMethodEntry, SQLRepository repository)
        {
            this.repository = repository as SQLRepository;
            this.xmlMethodEntry = xmlMethodEntry;
        }

        #region IDualMethod Members

        public bool Abstract
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Behavior
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Behaviour
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string ClassifierID
        {
            get
            {
                return EAEcoreAddin.Util.EAUtil.getXMLNodeContentFromSQLQueryString(xmlMethodEntry, "Classifier")[0];
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Code
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Concurrency
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string GetLastError()
        {
            throw new NotImplementedException();
        }

        public bool IsConst
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public bool IsLeaf
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public bool IsPure
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public bool IsQuery
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public bool IsRoot
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public bool IsStatic
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public bool IsSynchronized
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string MethodGUID
        {
            get
            {
                return EAEcoreAddin.Util.EAUtil.getXMLNodeContentFromSQLQueryString(xmlMethodEntry, "ea_guid")[0];
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public int MethodID
        {
            get 
            {

                return int.Parse(EAEcoreAddin.Util.EAUtil.getXMLNodeContentFromSQLQueryString(xmlMethodEntry, "OperationID")[0]); 
            }
        }

        public string Name
        {
            get
            {
                return EAEcoreAddin.Util.EAUtil.getXMLNodeContentFromSQLQueryString(xmlMethodEntry, "Name")[0];
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Notes
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public EA.ObjectType ObjectType
        {
            get { throw new NotImplementedException(); }
        }

        
        public EA.Collection Parameters
        {
            get 
            {
                EA.Collection parameters = new EACollection();
                String[] paramss = null;
                if (repository.FullDatabaseCheckout)
                {
                    paramss = repository.t_operationparamsOperationID.GetValues(MethodID.ToString());
                }
                else
                {
                    String sqlqry = repository.SQLQuery("select * from t_operationparams where OperationID = " + MethodID);
                    List<String> paramets = EAEcoreAddin.Util.EAUtil.getXMLNodeContentFromSQLQueryString(sqlqry, "Row");
                    if (!(paramets.Count  == 0) && !( paramets[0] == ""))
                    {
                        paramss = paramets.ToArray();    
                    }
                        
                }
                if (paramss == null)
                    return parameters;

                
                for (int i = 0; parameters.Count != paramss.Length; )
                {
                    foreach (String param in paramss)
                    {
                        if (param != "")
                        {
                            int pos = int.Parse(EAEcoreAddin.Util.EAUtil.getXMLNodeContentFromSQLQueryString(param, "Pos")[0]);
                            if (pos == i)
                            {
                                EA.Parameter actParam = new EAParameter(repository, param);
                                (parameters as EACollection).AddNew(actParam);

                            }
                        }
                    }
                    i++;
                }
                
                return parameters;
            }
        }

        public int ParentID
        {
            get 
            {
                return int.Parse(EAEcoreAddin.Util.EAUtil.getXMLNodeContentFromSQLQueryString(xmlMethodEntry, "Object_ID")[0]);
            }
        }

        public int Pos
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public EA.Collection PostConditions
        {
            get { throw new NotImplementedException(); }
        }

        public EA.Collection PreConditions
        {
            get { throw new NotImplementedException(); }
        }

        public bool ReturnIsArray
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string ReturnType
        {
            get
            {
                return EAEcoreAddin.Util.EAUtil.getXMLNodeContentFromSQLQueryString(xmlMethodEntry, "Type")[0];
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string StateFlags
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Stereotype
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string StereotypeEx
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string Style
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string StyleEx
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public EA.Collection TaggedValues
        {
            get { throw new NotImplementedException(); }
        }

        public string Throws
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public bool Update()
        {
            throw new NotImplementedException();
        }

        public string Visibility
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion


        public string Alias
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }
}
